﻿using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;

namespace MyRoguelike.Tools
{
    static class ResourceManager
    {
        static private Microsoft.Xna.Framework.Game _game;

        // List of texture
        static private Dictionary<string, Texture2D> _lstTextures 
            = new Dictionary<string, Texture2D>();

        // List of font
        static private Dictionary<string, SpriteFont> _lstFonts
            = new Dictionary<string, SpriteFont>();

        static public Dictionary<string, Texture2D> Textures
        {
            get { return _lstTextures; }
        }

        static public Dictionary<string, SpriteFont> Fonts
        {
            get { return _lstFonts; }
        }

        static public Microsoft.Xna.Framework.Game Game
        {
            get { return _game; }
        }

        static public void Initialize(Microsoft.Xna.Framework.Game game)
        {
            _game = game;
        }

        /// <summary>
        /// Adding texture to manager
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="path">Path of texture file</param>
        static public Texture2D AddTexture(string name, string path)
        {
            if (!_lstTextures.ContainsKey(name))
            {
                _lstTextures.Add(name, _game.Content.Load<Texture2D>(path));
                return _lstTextures[name];
            }

            return null;
        }

        /// <summary>
        /// Adding font to manager
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="path">Path of texture file</param>
        /// <returns></returns>
        static public SpriteFont AddFont(string name, string path)
        {
            if (!_lstFonts.ContainsKey(name))
            {
                _lstFonts.Add(name, _game.Content.Load<SpriteFont>(path));
                return _lstFonts[name];
            }

            return null;
        }

        /// <summary>
        /// Delete texture from manager
        /// </summary>
        /// <param name="name">Name</param>
        static public void DelTexture(string name)
        {
            if (_lstTextures.ContainsKey(name))
            {
                _lstTextures[name].Dispose();
                _lstTextures.Remove(name);
            }
        }

        /// <summary>
        /// Delete font from manager
        /// </summary>
        /// <param name="name">Name</param>
        static public void DelFont(string name)
        {
            if (_lstFonts.ContainsKey(name))
                _lstFonts.Remove(name);
        }
    }
}
